﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CIT.WMS.houseWork
{
    public partial class Form_SendDataToPVS : Form
    {
        public Form_SendDataToPVS()
        {
            InitializeComponent();
        }


        string woCode = string.Empty;
        string partNum = string.Empty;
        private void txtSfcNO_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                lab_msg.Text = string.Empty;
                if (string.IsNullOrEmpty(txtSfcNO.Text.Trim()))
                {
                    lab_msg.Text = "制令单不能为空";
                    txtSfcNO.SelectAll();
                    txtSfcNO.Focus();
                    return;
                }
                woCode = string.Empty;
                string sql = string.Format("SELECT *  FROM dbo.SfcDatProduct WHERE SfcNo='{0}'", txtSfcNO.Text.Trim());
                DataTable dtWocode = Utils.NMS.QueryDataTable(Utils.uContext, sql, new CIT.WMS.MESWcf.CmdParameter[0]);
                if (dtWocode.Rows.Count > 0)
                {
                    woCode = dtWocode.Rows[0]["WoCode"].ToString();
                    txtReelid.SelectAll();
                    txtReelid.Focus();
                }
            }
        }

        private void txtReelid_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                if (string.IsNullOrEmpty(txtReelid.Text.Trim()))
                {
                    lab_msg.Text = "Reelid不能为空";
                    txtSfcNO.SelectAll();
                    txtSfcNO.Focus();
                    return;
                }
                string sql = string.Format("SELECT *  FROM dbo.T_Bllb_StockInfo_tbsi WHERE SerialNumber='{0}'", txtReelid.Text.Trim());
                DataTable dtStock = Utils.NMS.QueryDataTable(Utils.uContext, sql, new CIT.WMS.MESWcf.CmdParameter[0]);
                if (dtStock.Rows.Count > 0)
                {
                    txtQty.Text = dtStock.Rows[0]["QTY"].ToString();
                    partNum = dtStock.Rows[0]["MaterialCode"].ToString();
                    txtQty.Focus();
                }
                else
                {
                    lab_msg.Text = "Reelid错误";
                    txtSfcNO.SelectAll();
                    txtSfcNO.Focus();
                    return;
                }
            }
        }
        bool flag = true;
        bool result = true;
        private void txtQty_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                if (string.IsNullOrEmpty(txtQty.Text.Trim()))
                {
                    lab_msg.Text = "Qty不能为空";
                    txtSfcNO.SelectAll();
                    txtSfcNO.Focus();
                    return;
                }
                string sql = string.Format(@"IF NOT EXISTS(SELECT *  FROM dbo.PUB_UniqueCodeInLine WHERE UniqueCode='{0}')
		BEGIN
			INSERT INTO dbo.PUB_UniqueCodeInLine
			        (  
					  WorkOrderNo,
					  MOrderNo,
					  UniqueCode,
					  MatrCode,
					  Qty)
					  VALUES('{0}','{1}','{2}','{3}','{4}')

		END",woCode,txtSfcNO.Text.Trim(),txtReelid.Text.Trim(),partNum,txtQty.Text.Trim());
                Utils.NMS.Exectransql(Utils.uContext, sql, new CIT.WMS.MESWcf.CmdParameter[0], out flag, out result);
                //sql = string.Format(string.Format(@" UPDATE dbo.T_Bllb_StockInfo_tbsi SET Lock_Flag='7',Storage_SN='',Area_SN='',Location_SN='' WHERE SerialNumber='{0}' ",txtReelid.Text.Trim()));
                //Utils.NMS.Exectransql(Utils.uContext, sql, new CIT.WMS.MESWcf.CmdParameter[0], out flag, out result);
                //sql = string.Format(@"");
                if (flag)
                {
                    txtReelid.Text = string.Empty;
                    txtReelid.Focus();
                    lab_msg.Text = "成功";
                }
            }
        }
    }
}